package com.ruoyi.project.user.userprivilege.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.user.userprivilege.domain.UserPrivilege;
import com.ruoyi.project.user.userprivilege.mapper.UserPrivilegeMapper;
import com.ruoyi.project.user.userprivilege.service.IUserPrivilegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户特权Service业务层处理
 *
 * @author shixiangwen
 * @date 2022-10-11
 */
@Service
@DataSource(DataSourceType.ACCOUNT)
public class UserPrivilegeServiceImpl implements IUserPrivilegeService {

    @Autowired
    private UserPrivilegeMapper userPrivilegeMapper;

    /**
     * 查询用户特权
     *
     * @param id 用户特权ID
     * @return 用户特权
     */
    @Override
    public UserPrivilege selectUserPrivilegeById(Long id) {
        return userPrivilegeMapper.selectUserPrivilegeById(id);
    }

    @Override
    public UserPrivilege selectUserPrivilege(UserPrivilege userPrivilege) {
        return userPrivilegeMapper.selectUserPrivilege(userPrivilege);
    }

    /**
     * 查询用户特权列表
     *
     * @param userPrivilege 用户特权
     * @return 用户特权
     */
    @Override
    public List<UserPrivilege> selectUserPrivilegeList(UserPrivilege userPrivilege) {
        return userPrivilegeMapper.selectUserPrivilegeList(userPrivilege);
    }

    /**
     * 新增用户特权
     *
     * @param userPrivilege 用户特权
     * @return 结果
     */
    @Override
    public int insertUserPrivilege(UserPrivilege userPrivilege) {
        userPrivilege.setCreateTime(DateUtils.getNowDate());
        return userPrivilegeMapper.insertUserPrivilege(userPrivilege);
    }

    /**
     * 修改用户特权
     *
     * @param userPrivilege 用户特权
     * @return 结果
     */
    @Override
    public int updateUserPrivilege(UserPrivilege userPrivilege) {
        userPrivilege.setUpdateTime(DateUtils.getNowDate());
        return userPrivilegeMapper.updateUserPrivilege(userPrivilege);
    }

    /**
     * 删除用户特权对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteUserPrivilegeByIds(String ids) {
        return userPrivilegeMapper.deleteUserPrivilegeByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除用户特权信息
     *
     * @param id 用户特权ID
     * @return 结果
     */
    @Override
    public int deleteUserPrivilegeById(Long id) {
        return userPrivilegeMapper.deleteUserPrivilegeById(id);
    }
}
